﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Serialization;

namespace CrazyWorship1
{

    public class Client : IXmlSerializable
    {
        public Client()
        {
        }
        ClientList _parent;
        public Client(ClientList parent)
        {
            _parent = parent;
        }
        public Client(ClientList parent, string clientUrl, bool connected)
        {
            _clientUrl = clientUrl;
            _connected = connected;
            _parent = parent;
        }
        public Client(ClientList parent, string clientUrl)
        {
            _clientUrl = clientUrl;
            _connected = false;
            _parent = parent;
        }
        string _clientUrl;
        public string ClientUrl
        {
            get
            {
                return _clientUrl;

            }
            set
            {
                _clientUrl = value;
            }
        }
        public ClientList Parent
        {
            get
            {
                return _parent;

            }
            set
            {
                _parent = value;
            }
        }
        bool _connected;
        public bool Connected
        {
            get
            {
                return _connected;
            }
            set
            {
                _connected = value;
            }
        }
        public ScreenInfoList ScreenInfoList
        {
            get
            {
                ScreenInfoList l = new ScreenInfoList();
                foreach (ScreenInfo info in Parent.ScreenInfoList)
                {
                    if (info.ClientUrl == this.ClientUrl)
                        l.Add(info);
                }
                return l;
            }
        }

        #region IXmlSerializable Members

        public System.Xml.Schema.XmlSchema GetSchema()
        {
            return null;
        }

        public void ReadXml(System.Xml.XmlReader reader)
        {
            reader.ReadStartElement("Client");
            _clientUrl = reader.ReadElementContentAsString("_clientUrl", "");
            _connected = reader.ReadElementContentAsBoolean("_connected", "");
            reader.ReadEndElement();
            reader.MoveToContent();

        }

        public void WriteXml(System.Xml.XmlWriter writer)
        {
            writer.WriteStartElement("Client");
            writer.WriteElementString("_clientUrl", _clientUrl);
            writer.WriteStartElement("_connected", "");
            writer.WriteValue(_connected);
            writer.WriteEndElement();
            writer.WriteEndElement();
        }

        #endregion
    }

}
